package com.kele.algorithm;

import com.kele.ddl.CreateTable;
import com.kele.entity.DbModel;
import com.kele.entity.ListModel;
import com.kele.job.FindDb;
import com.kele.utils.DbDetailsUtils;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * SHA算法
 */
public class AlgorithmUtils {

     public static String src = "";
     public static String s = "";

    public static String getSrc() {
        return src;
    }

    public static void setSrc(String src) {
        AlgorithmUtils.src = src;
    }

    public static void main(String[] args) throws SQLException {

//        FindDb findDb=new FindDb();
//
//        List<String> list = findDb.execute();
//        System.out.println(list);

//        for (int i = 0; i <list.size() ; i++) {
//            System.out.println(list.get(i));
//        }



//        for (int i=0;i<list.size();i++){
//            src=list.get(i);
//
//            jdkSHA1(src);
//        }


        String sql="select * from  user";
        List list1 = DbDetailsUtils.execute(sql);

        for (int i=0;i<list1.size();i++){
            src= (String) list1.get(i);

            //System.out.println(jdkSHA1(src));
            System.out.println("====================加密之前==================");
            System.out.println(src);

            System.out.println("=====================加密之后==================");
            System.out.println(jdkSHA1(src));
        }

//        ccSHA1();
    }

    public static String jdkSHA1(String src) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(src.getBytes());
            //System.out.println("jdk sha-1 : " + Hex.encodeHexString(md.digest()));
            s = Hex.encodeHexString(md.digest());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return s;
    }




//    public static void ccSHA1() {
//        System.out.println("cc sha1 - 1 :" + DigestUtils.sha1Hex(src.getBytes()));
//        System.out.println("cc sha1 - 2 :" + DigestUtils.sha1Hex(src));
//    }



}
